package com.example.fruitdemo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.fruitdemo.pojo.User;
import com.example.fruitdemo.ruslet.R;
import com.example.fruitdemo.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/api")
public class LoginController {
    @Autowired
   private UserService userService;
    @PostMapping("/login")
    public R<String> login(@RequestBody User user , HttpServletResponse response) throws IOException {
        return userService.login(user, response);
    }
    //查询令牌跳转登录页面以及图标展示
    @GetMapping("/login/query")
    public R<String> loginquery(HttpServletRequest request){

        if(request.getHeader("authorization")==null||request.getHeader("authorization").isEmpty())
            return R.Err("未授权！");
        else return R.Ok();
    }

    @GetMapping("/loginout")
    public R<String> loginout( String authorization){
       return userService.loginout(authorization);
    }

//    //俩图标的展示
//    @GetMapping("/login/show")
//    public R<String> loginshow(HttpServletRequest request){
//        if(request)
//    }
}
